package com.jacken.mars.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jacken.mars.commons.annotation.BaseAnnotationNote;
import com.jacken.mars.entity.req.SysDeptReq;
import com.jacken.mars.entity.resp.R;
import com.jacken.mars.entity.base.PageInfo;
import com.jacken.mars.entity.base.BasePageRequest;
import com.jacken.mars.entity.vo.SysDeptListVo;
import com.jacken.mars.entity.vo.SysMenuListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import lombok.AllArgsConstructor;

import java.util.Arrays;
import java.util.List;

import com.jacken.mars.entity.SysDept;
import com.jacken.mars.service.ISysDeptService;

/**
 * SysDept 控制层
 *
 * @Author wq
 * @Date 2021-02-04
 **/
@RestController
@RequestMapping("admin/sysDept")
@AllArgsConstructor
public class SysDeptController {

    private final ISysDeptService sysDeptService;


    /**
     * 添加部门
     *
     * @param req
     * @return
     */
    @PostMapping("/add")
    @BaseAnnotationNote
    public R add(@RequestBody SysDeptReq req) {
        sysDeptService.add(req);
        return R.success("添加成功");
    }

    /**
     * 删除部门
     *
     * @param id
     * @return
     */
    @GetMapping("/delete")
    @BaseAnnotationNote
    public R delete(@RequestParam("id") Integer id) {
        sysDeptService.delete(id);
        return R.success("删除成功");
    }

    /**
     * 更新部门
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    @BaseAnnotationNote
    public R update(@RequestBody SysDeptReq req) {
        sysDeptService.update(req);
        return R.success("更新成功");
    }

    /**
     * 详情部门
     *
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @BaseAnnotationNote
    public R detail(@RequestParam("id") Integer id) {
        return R.success(sysDeptService.getDeptDetail(id));
    }

    /**
     * 部门名称
     *
     * @param id       部门ID
     * @param deptName 部门名称
     * @return
     */
    @GetMapping("/list")
    @BaseAnnotationNote
    public R list(Integer id, String deptName) {
        List<SysDeptListVo> list = sysDeptService.getList(id, deptName);
        return R.success(list);
    }

    /**
     * 树形部门
     *
     * @return
     */
    @GetMapping("/tree")
    @BaseAnnotationNote
    public R treeDept() {
        return R.success(sysDeptService.treeDept());
    }

}